<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

</body>
<script>
	Function.prototype.myApply = function(context){
		if(context === null || context === undefined){
			context = window;
		}else if(typeof context !== "object" && typeof context !== "function" ){
			context = new Object(context);
		}
		// 将函数作为对象的属性值。运行对象下的属性即可实现隐式绑定
		const fnName = Math.random().toString(36).slice(2);
		context[fnName] = this;
		// 1
		// context[fnName](...arr);
		
		// 2
		// console.log(Array.from(arguments[1]).join(","));
		// console.log("context[fnName](Array.from(arguments[1]).join(','))")
		const argStr = Array.from(arguments[1]).join(',');
		const evalStr = "context[fnName]("+argStr+")";
		console.log(evalStr);
		// eval(evalStr);
		eval( "context[fnName]("+argStr+")")
	}
	function run(a,b,c,d){
		console.log("run",this,a,b,c,d);
	}
	run.myApply(1,[1,2,3,4]);
</script>
</html>